class DoublyLinkedList{
    constructor(){
        this.tail = null;
        this.head = null;
        this.length =0;
    }
    append = (data)=>{
        let dnode = new DNode(data)
        if (this.length==0) {
            this.head = this.tail = dnode;
            dnode.next = dnode.prev = this;
            this.length++;
        }else{
            dnode.next = this.head;
            dnode.prev = this;
            this.head.prev = dnode;
            this.head = dnode;
            this.length++;
        }  
    }
    toString_Zh = ()=>{
        let index = 0;
        let ListString = ''
        let current = this.head;
        while (index<this.length) {
            ListString+=current.data+' '
            current = current.next 
            index++;  
        }
        return ListString
    }
    toString_Fa = ()=>{
        let index = 0;
        let ListString = ''
        let current = this.tail;
        while (index<this.length) {
            ListString+=current.data+' '
            current = current.prev 
            index++;  
        }
        return ListString
    }
}
class DNode{
    constructor(data){
        this.prev = null;
        this.next = null;
        this.data = data
    }
}